﻿Imports System.Text
Imports System.Net.Sockets
Imports System.Net
Imports System.Drawing

Public Class WhoisResolver

    Dim _country_code As String = ""


    ''' <summary>
    ''' Funktion zum umsetzten der IP-Addresse in einen Ländercode
    ''' </summary>
    Public Function Resolve(ByVal _ip As String) As String


            Dim XMLReader As New Xml.XmlDocument
            Dim xmlKD As Xml.XmlElement

        Debug.WriteLine(String.Format("Ermittle WohIs für IP {0}", _ip))

            _country_code = ""

            XMLReader.Load("http://xml.utrace.de/?query=" & _ip)

            xmlKD = CType(XMLReader.DocumentElement.ChildNodes(0), Xml.XmlElement)

            For Each _node As Xml.XmlNode In xmlKD.ChildNodes

                If _node.Name = "countrycode" Then

                    _country_code = _node.ChildNodes(0).Value

                End If

            Next

            Debug.WriteLine(String.Format("Ermittle ermittelter CounterCode: {0}", _country_code))

            Return _country_code

    End Function

    Public Function DownloadFlagImage(ByVal _countrycode As String) As Image

        Dim _flag As Image
        Dim _tools As New Tools

        _flag = _tools.DownloadImage("http://n1.dlcache.com/flags/" & _country_code.ToLower & ".gif")

        Return _flag


    End Function

End Class